//
//  BeforeVC.m
//  AnimationRecommend
//
//  Created by ljm on 2017/2/28.
//  Copyright © 2017年 ljm. All rights reserved.
//

#import "BeforeVC.h"
#import <WebKit/WebKit.h>

@interface BeforeVC ()

@end

@implementation BeforeVC

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    self.tabBarController.tabBar.hidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor clearColor];
    
    
    WKWebView *wview = [[WKWebView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:wview];

    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:wview animated:YES];
    hud.mode = MBProgressHUDModeIndeterminate;
    hud.label.text = @"加载中...";
    
    [[NetworkTools shareTools] requestWithMethod:GET andURL:self.url andParameters:nil andCallBack:^(id data, NSError *error) {
        if (!error) {
            
            NSDictionary *post = data[@"post"];
            NSString *string =  post[@"content"];
            
            NSString *htmls = [NSString stringWithFormat:@"<html> \n"
                               "<head> \n"
                               "<style type=\"text/css\"> \n"
                               "body {font-size:25px;} \n"
                               "body {background-color:%@;} \n"
                               "body {font-family:%@;} \n"
                               "</style> \n"
                               "</head> \n"
                               "<body>"
                               "<script type='text/javascript'>"
                               "window.onload = function(){\n"
                               "var $img = document.getElementsByTagName('img');\n"
                               "for(var p in  $img){\n"
                               " $img[p].style.width = '100%%';\n"
                               "$img[p].style.height ='50%%'\n"
                               "}\n"
                               "}"
                               "</script>%@"
                               "</body>"
                               "</html>",@"#E2EAF2",@"MF-ManYu-Noncommercial-Regular",string];
            [wview loadHTMLString:htmls baseURL:nil];
            [hud hideAnimated:YES afterDelay:1.f];

        }else {
            NSLog(@"---------error-----------%@",error);
        }
    }];
    
//        [[NetworkTools shareTools]  GET:self.url parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//            NSLog(@"------------------- \n %@",responseObject);
//            NSDictionary *post = responseObject[@"post"];
//            NSString *string =  post[@"content"];
//        
//            NSString *htmls = [NSString stringWithFormat:@"<html> \n"
//                               "<head> \n"
//                               "<style type=\"text/css\"> \n"
//                               "body {font-size:25px;} \n"
//                               "body {background-color:%@;} \n"
//                               "body {font-family:%@;} \n"
//                               "</style> \n"
//                               "</head> \n"
//                               "<body>"
//                               "<script type='text/javascript'>"
//                               "window.onload = function(){\n"
//                               "var $img = document.getElementsByTagName('img');\n"
//                               "for(var p in  $img){\n"
//                               " $img[p].style.width = '100%%';\n"
//                               "$img[p].style.height ='50%%'\n"
//                               "}\n"
//                               "}"
//                               "</script>%@"
//                               "</body>"
//                               "</html>",@"#E2EAF2",@"MF-ManYu-Noncommercial-Regular",string];
//            [wview loadHTMLString:htmls baseURL:nil];
//            [hud hideAnimated:YES afterDelay:1.f];
//
//        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//            
//            NSLog(@"%@",error);
//        }];
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
